import asyncio
import random

c = (
    '\033[0m',   # End of color
    "\033[36m",  # Cyan
    "\033[91m",  # Red
    "\033[35m",  # Magenta
)


async def make_random(idx: int, thresh: int = 6) -> int:
    xidx = (idx + 1) % len(c)
    print(f"{c[xidx]} Init make_random({idx}, {thresh}){c[0]}")

    def gen():
        return random.randint(0, 10)

    i = gen()
    while i <= thresh:
        print(f"{c[xidx]} make_random({idx}, {thresh}) --> {i} too low; retrying ...{c[0]}")
        await asyncio.sleep(xidx)
        i = gen()

    print(f"{c[xidx]} ----> Finished: make_random({idx}, {thresh}) --> {i}{c[0]}")
    return i


if '__main__' == __name__:
    random.seed(444)
    # res = await asyncio.gather(*[make_random(i, 10 - i - 1) for i in range(3)])  # SyntaxError: 'await' outside function
    res = asyncio.gather(*[make_random(i, 10 - i - 1) for i in range(3)])  # res: <_GatheringFuture pending>
    print()
    print(f"res: {res}")
